package elements;

import java.util.ArrayList;
import java.util.List;

import si2.robo.AspiradorModel;

public class GarbageGroup extends Element{
	
	private List<Garbage> garbageList;
	private ArrayList<Integer> types;
	private int time;
	private int id;

	public GarbageGroup(int id, int x, int y, AspiradorModel model){
		super(x, y);
		
		this.id = id;	
		
		do {
			garbageList = new ArrayList<Garbage>();
			Garbage g = new Garbage(x, y, (int)(Math.pow(2, 3+(int)((Math.random())*3))));
			garbageList.add(g);
			g = new Garbage(x+1, y, (int)(Math.pow(2, 3+(int)((Math.random())*3))));
			garbageList.add(g);
			g = new Garbage(x, y+1, (int)(Math.pow(2, 3+(int)((Math.random())*3))));
			garbageList.add(g);
			g = new Garbage(x+1, y+1, (int)(Math.pow(2, 3+(int)((Math.random())*3))));
			garbageList.add(g);
		} while (!isValid());
		
		for (int i = 0; i < garbageList.size(); i++) {
			Garbage g = garbageList.get(i);
			
			model.add(g.getType(), g.getX(), g.getY());
		}
		
		types = new ArrayList<Integer>();		
		boolean add;
		for(Garbage g : garbageList) {
			add = true;
			for(Integer type : types) {
				if(type == g.getType()) {
					add = false;
					break;
				}
			}
			if(add) types.add(g.getType());
		}	
		
		time = 1;
	}
	
	public ArrayList<Integer> getTypes() {
		return types;
	}	

	public void setTypes(ArrayList<Integer> types) {
		this.types = types;
	}

	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
	}

	public List<Garbage> getGarbageList() {
		return garbageList;
	}

	public void setGarbageList(List<Garbage> garbageList) {
		this.garbageList = garbageList;
	}	
	
	public int getTime() {
		return time;
	}

	public void setTime(int time) {
		this.time = time;
	}	
	
	public boolean isValid() {
		for (int i = 1; i < garbageList.size(); i++) {
			//System.out.println("Type0: " + garbageList.get(0).getType() + " " + garbageList.get(i).getType());
			if (garbageList.get(0).getType() != garbageList.get(i).getType()) {
				return true;
			}
		}
		return false;
	}
}
